﻿using NPinyin;
using System;
using System.Collections.Generic;
using System.Text;

namespace PeiYue.Common.Helper
{
    public class NPinyinHelper
    {
        /// <summary>
        /// 中文首字母大写
        /// </summary>
        /// <param name="str">中文</param>
        /// <returns></returns>
        public static string GetSpellCode(string str)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);//注册编码对象
            Encoding gb2312 = Encoding.GetEncoding("GB2312");
            string strA = Pinyin.ConvertEncoding(str, Encoding.UTF8, gb2312);
            //首字母
            string strB = Pinyin.GetInitials(strA, gb2312);
            //拼音 　　　　　　　//string strC = Pinyin.GetPinyin(str);
            return strB;
        }
    }
}
